const app = getApp()
Page({
  data: {
    loading:true,
    page:0,
    item:[],
    topnone:{},
    showbar:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getTopTirst();
    this.getTop();
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(()=>{
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.setData({
      item: [],
      loading:true
    });
    this.data.page =  0;
    this.getTop();
  },
  //底部加载
  onReachBottom: function () {
    this.setData({
      loading: true,
    });
    this.getTop();
  },
 //获取API
  getTopTirst: function () {
    app.api().Get('api/v1/smartbc/ranking/topfirst',(result) => {
      if (result.code == 200) {
        this.setData({
          topnone:result.data
        })
      }
    })
  },
 //获取API
  getTop: function () {
    var item = this.data.item;
    if (this.data.loading) {
      var param = {
        page: this.data.page + 1,
      }
      app.api().Get('api/v1/smartbc/ranking/topMoney',param,(result) => {
        if (result.code == 200) {
          for (let i in result.data) {
            item.push(result.data[i]);
          }
          this.setData({
            item: item,
          });
          this.data.page =  param.page;
        }
        this.setData({
          loading: false
        })
      })
    }
  },
  //转发
  onShareAppMessage: function (res) {
    return {
      title: '我在'+app.appname+'消费省钱了~一起来省钱把.',
      path: '/page/top?ucode='+app.globalData.ucode
    }
  }
})